
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       sensor_airspeed_ms5525.h
  * @author     baiyang
  * @date       2023-8-1
  ******************************************************************************
  */

#pragma once

#ifdef __cplusplus
extern "C"{
#endif

/*----------------------------------include-----------------------------------*/
#include "sensor_airspeed_backend.h"

#include <device_manager/dev_mgr.h>
/*-----------------------------------macro------------------------------------*/
#ifndef MB_AIRSPEED_MS5525_ENABLED
#define MB_AIRSPEED_MS5525_ENABLED MB_AIRSPEED_BACKEND_DEFAULT_ENABLED
#endif

#if MB_AIRSPEED_MS5525_ENABLED
/*----------------------------------typedef-----------------------------------*/
enum MS5525_ADDR {
    MS5525_ADDR_1    = 0,
    MS5525_ADDR_2    = 1,
    MS5525_ADDR_AUTO = 255, // does not need to be 255, just needs to be out of the address array
};

typedef struct sensor_as_ms5525 *sensor_as_ms5525_t;
typedef const struct sensor_as_ms5525 *sensor_as_ms5525_const_t;

struct sensor_as_ms5525 {
    struct sensor_as_backend backend;

    float pressure;
    float temperature;
    float temperature_sum;
    float pressure_sum;
    uint32_t temp_count;
    uint32_t press_count;
    
    uint32_t last_sample_time_ms;

    uint16_t prom[8];
    uint8_t state;
    int32_t D1;
    int32_t D2;
    uint32_t command_send_us;
    bool ignore_next;
    uint8_t cmd_sent;
    enum MS5525_ADDR _address;

    gp_device_t dev;
};
/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
void sensor_as_ms5525_ctor(sensor_as_ms5525_t ms5525, uint8_t _instance, enum MS5525_ADDR address);
sensor_as_backend_t sensor_as_ms5525_probe(uint8_t _instance, enum MS5525_ADDR address);
/*------------------------------------test------------------------------------*/
#endif

#ifdef __cplusplus
}
#endif



